const baseURL = 'http://192.168.1.223:8080'; // 替换为您的实际API基础URL

const request = async (url, options = {}) => {
    try {
      const response = await fetch(baseURL + url, {
        method: options.method || 'GET',
        headers: {
          'Content-Type': 'application/json',
          ...options.headers
        },
        body: options.method === 'POST' || options.method === 'PUT' ? JSON.stringify(options.data) : undefined
      });
  
      if (!response.ok) {
        throw new Error(`Request failed with status code ${response.status}`);
      }
  
      const data = await response.text();
      return data;
    } catch (error) {
      throw new Error(`Request failed: ${error.message}`);
    }
  };
  
  export default request;